	<script type="text/javascript">
		$(document).ready(function(){
			$("#datepicker1").datepicker();
		});
	</script>
		<div class="row">
		    <div class="col-xs-12">
		        <div class="box box-primary">
		            <div class="box-header">
		                <h3 class="box-title">Tambah Data Klaim Obat & ABHP</h3>
		            </div><!-- /.box-header -->
		            <?php echo form_open('apotik/save', array('role' => 'form', 'id' => 'form'));?>
		            <div class="box-body col-xs-12 col-lg-6">				        
	                    <!-- text input -->
	                    <div class="form-group">
	                        <label>Kode Klaim</label>
	                        <div class="input-group input-group-sm">
	                       		<input class="form-control" name="kd_klaim" id="kd_klaim" type="text" placeholder="Masukkan kode klaim" style="z-index:0;">
	                       		<span class="input-group-btn">
	                       			<a class="btn btn-info btn-flat" href="#" onClick="return kd_peserta()"><i class="fa fa-check"></i></a>
	                       		</span>
	                        </div>
	                    </div>
	                    <div class="form-group">
	                        <label>No. Peserta</label>
	                       	<input class="form-control input-sm" name="nopeserta" id="nopeserta" type="text" disabled>
	                    </div>
	                    <div class="form-group">
	                        <label>Nama Peserta</label>
	                       	<input class="form-control input-sm" name="nama" id="nama" type="text" readonly="">
	                    </div>
	                </div>
	                <div class="box-body col-xs-12 col-lg-6">
	                     <div class="form-group">
	                        <label>TTL Peserta</label>
	                       	<input class="form-control input-sm" name="ttl" id="ttl" type="text" disabled>
	                    </div>
	                     <div class="form-group">
	                        <label>Alamat Peserta</label>
	                       	<input class="form-control input-sm" name="alamat" id="alamat" type="text" disabled>
	                    </div>
	                    <div class="form-group">
		                    <label>Tanggal Transaksi</label>
		                    <input class="form-control input-sm" name="tgl_transaksi" id="datepicker1" value="<?= $tgl_transaksi; ?>" type="text" placeholder="Tanggal Transaksi..."> 
		                 	<input name="no" id="no" type="hidden">
		                 </div>
		            </div>
		            <div class="box-body" id="tab" style="display:none;">

						  <!-- Tab panes -->
						  <div class="tab-content" style="width:100%">
						    <div role="tabpanel" class="tab-pane fade in active" id="layanan">
						    	<label>Obat & ABHP</label><br/><!--
						    	<label class="pull-right">Total </label><input type="text" name="ltotal" id="ltotal" disabled="">
								-->
					            <table class="table table-borderless table-condensed table-striped">
					            	<tr>
					              		<th></th>
					              		<th></th>
					              		<th></th>
					              		<th></th>
					              		<th></th>
					              		<th></th>
					              		<th align="right">
					              			<a href="#tbl-obat" id="add_obat" class="btn btn-success btn-xs btn-flat pull-right">
						                      <i class="fa fa-fw fa-plus"></i>
						                    </a>
					              		</th>
					              	</tr>
					              	<tr>
					              		<th width="5%">#</th>
					              		<th width="15%">Obat/ABHP</th>
					              		<th width="10%">Tarif Perda</th>
					              		<th width="5%">Jumlah</th>
					              		<th width="10%">Tarif Diminta</th>
					              		<th width="12%">Subtotal</th>
					              		<th width="5%"></th>
					              	</tr>
					            <tbody id="tbl-obat">
					              	
					            </tbody>	
					              	
					            </table>
						    </div>
						  </div>

					<?php echo form_close();?>
		            </div>
		            <div class="box-footer col-xs-12">
                         <button type="submit" class="btn btn-sm btn-primary btn-flat"><i class="fa fa-floppy-o"></i> Simpan</button>
                    </div>
		            <div class="clearfix"></div>		                   
                    
		        </div><!-- /.box -->                            
		    </div>
		</div>

		<script type="text/javascript">
		$(document).ready(function () {
			$("#master_diagnosa").select2({
			    placeholder: "Pilih Diagnosa"
			});
		});
		</script>
		<script>
		$("#form").validate({
			rules: {
				
				kd_klaim: {
					required: true
				},
			}
		});
		</script>
		<script type="text/javascript">
		  function kd_peserta(){
		    var send_data = {
		        kd_peserta: $("#kd_klaim").val(),
		        <?php echo $this->security->get_csrf_token_name(); ?>: "<?php echo $this->security->get_csrf_hash(); ?>",
		      };

		    $.ajax({
		      type: "POST",
		      url: "<?php echo base_url() ?>apotik/get_klaim",
		      data: send_data,
		      cache: false,
		      dataType: 'json',
		      success: function(msg){
		        $("#nama").val(msg.nama);
		        $("#nopeserta").val(msg.nopeserta);
		        $("#alamat").val(msg.alamat);
		        $("#ttl").val(msg.ttl);
		        if (msg.stts=="ada") {
		        	document.getElementById("tab").style.display = "inline-block";
		        	document.getElementById("kd_klaim2").value = $("#kd_klaim").val();
		        }else{
		        	document.getElementById("tab").style.display = "none";
		        };
		        
		      }
		    });
		    /*
		    //get klaim layanan
		    $.ajax({
			      url: "<?php echo base_url() ?>apotik/get_apotik_klaim/"+$('#kd_klaim').val()+"",
			      cache: false,
			      dataType: 'html',
			      success: function(msg){
			        $("#tbl-apotik").html(msg);
			      }
			    });
			
			 */
			// get layanan
		    $.ajax({
		        url: '<?php echo base_url() ?>apotik/get_apotik/'+$("#kd_klaim").val()+'',
			    //data: send_data,
			    cache: false,
			    dataType: 'html',
		        success: function(data){
		        	var arr = document.getElementsByClassName("obat");
		        	var tot =0;
		        	for(var i=0;i<arr.length;i++){
		        		if (parseInt(arr[i].value))
		        			 tot += parseInt(arr[i].value);
		        	}

		        	document.getElementById('tarif_perda').value=tot;

		            $("#pilih_obat").html(data);
		            $("#master_obat").select2({
			            placeholder: "Pilih Obat ABHP"
			        });
		        }
		    });
		  }
		  
		  

			/*
			function get_apotik_klaim()
			{
			    $.ajax({
			      url: "<?php echo base_url() ?>apotik/get_apotik_klaim/"+$('#kd_klaim').val()+"",
			      cache: false,
			      dataType: 'html',
			      success: function(msg){
			        $("#tbl-apotik").html(msg);
			      }
			    }); 
			}
			*/
			

		</script>

		
		<script type="text/javascript">
		//hitung sub total, pakai perulangan
		//hitung jmh baris berdsarkan className
		        $(document).ready(function () {
		            $('#jumlah').keyup(function(){
		                var jml = parseInt(document.getElementById("jumlah").value);
		                var tarif = parseInt(document.getElementById("tarif_diminta").value);
		                var tot=jml*tarif;
		                document.getElementById('subtotal').value = tot;

		                
		            });
		            $('#tarif_diminta').keyup(function(){
		                var jml = parseInt(document.getElementById("jumlah").value);
		                var tarif = parseInt(document.getElementById("tarif_diminta").value);
		                var tot=jml*tarif;
		                document.getElementById('subtotal').value = tot;
		            });
		        });

		</script>

		
		<script type="text/javascript">
			$(document).ready(function() {
	    		var a = 0;

	    		$("#add_obat").click(function(){
						a += 1;
			   		$('#tbl-obat').append(
								 '<tr class="obat" id="obat'+a+'">'
							 + '<td >'+a+'</td>'
							 + '<td ><select class="form-control input-sm master_obat" name="master_obat" id="master_obat'+a+'" style="width:250px;"></select></td>'
							 + '<td><input class="form-control input-sm tarif_perda" name="tarif_perda[]" id="tarif_perda'+a+'" type="text" disabled=""></td>'
							 + '<td><input class="form-control input-sm jumlah" name="jumlah[]" id="jumlah'+a+'" type="text" placeholder=""></td>'
							 + '<td><input class="form-control input-sm tarif_diminta" name="tarif_diminta[]" id="tarif_diminta'+a+'" type="text" placeholder="Tarif Diminta"></td>'
							 + '<td><input class="form-control input-sm subtotal" name="subtotal[]" id="subtotal'+a+'" type="text" disabled=""></td>'
							 + '<td><a class="btn btn-xs btn-danger btn-flat pull-right remove_item" id="remove_item" onclick="hapusObat(this)" href="#obat'+a+'" ><i class="fa fa-trash-o"></i></a></td>'
							 + '</tr>'
						);

			   		
			   		$.ajax({
				        url: '<?php echo base_url() ?>apotik/get_apotik/'+$("#kd_klaim").val()+'',
					    //data: send_data,
					    cache: false,
					    dataType: 'html',
				        success: function(data){
				            $("#master_obat"+a).html(data);
				            $("#master_obat"+a).select2({
					            placeholder: "Pilih Obat ABHP"
					        });
				        }
				    });
				    
				    $("#master_obat"+a).change(function()
					{
					    var data_send = {
					        obat: $("#master_obat"+a).val(),
					        <?php echo $this->security->get_csrf_token_name(); ?>: "<?php echo $this->security->get_csrf_hash(); ?>",
					      };
					    $.ajax({
					      type: "POST",
					      url: "<?php echo base_url() ?>apotik/get_obat_by",
					      data: data_send,
					      cache: false,
					      dataType: 'json',
					      success: function(msg){
					        $("#tarif_perda"+a).val(msg.harga);
					        $("#subtotal"+a).val(msg.harga);
					        $("#tarif_diminta"+a).val(msg.harga);
					        $("#kd_obat"+a).val(msg.kd_obat);
					        $("#jumlah"+a).val(msg.jumlah);
					      }
					    }); 
					});

					$('#jumlah'+a).keyup(function(){
		                var jml = parseInt(document.getElementById("jumlah"+a).value);
		                var tarif = parseInt(document.getElementById("tarif_diminta"+a).value);
		                var tot=jml*tarif;
		                document.getElementById('subtotal'+a).value = tot;

		                
		            });
		            $('#tarif_diminta'+a).keyup(function(){
		                var jml = parseInt(document.getElementById("jumlah"+a).value);
		                var tarif = parseInt(document.getElementById("tarif_diminta"+a).value);
		                var tot=jml*tarif;
		                document.getElementById('subtotal'+a).value = tot;
		            });

					});

					$(".remove_item").click(function(){
			        	$(this).parents(".obat").fadeOut();
			        	$(this).parents(".obat").remove();
	     		});

				
			});
			function hapusObat(obj){  
				    if (confirm('Apakah data akan dihapus ?')) {
				      obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
				    }
				  }
		</script>
		
		
		